﻿using App.Common;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(LevelMap))]
//[CanEditMultipleObjects]
public class EditMap : Editor
{
    private List<Vector2> pos2World;

    /**/private void OnEnable()
    {
        pos2World = new List<Vector2>();
        //x
        pos2World.Add(new Vector2(Data.Length * Mathf.Sqrt(3) / 2, Data.Length / 2));
        //y
        pos2World.Add(new Vector2(-Data.Length * Mathf.Sqrt(3) / 2, Data.Length / 2));
        //z
        pos2World.Add(new Vector2(0, -Data.Length));
    }

    private void OnSceneGUI()
    {
        //Debug.Log("On Scene");
        LevelMap levelMap = target as LevelMap;
        for(int i = 0; i < levelMap.transform.childCount; i++)
        {
            hexagon child = levelMap.transform.GetChild(i).GetComponent<hexagon>();
            //Debug.Log(child.gameObject.name);
            child.transform.position =getWorldPos(child.Pos);
            //Debug.Log(getWorldPos(child.Pos).ToString());
        }
    }

    private Vector2 getWorldPos(Vector3 vec)
    {
        Vector2 res = new Vector2(0, 0);
        res += (vec.x * pos2World[0] + vec.y * pos2World[1] + vec.z * pos2World[2]);
        return res;
    }
}
